package com.itheima.fengkuanglianxi.bookmanager.bookservice;

import com.itheima.fengkuanglianxi.bookmanager.bookdao.Book2Dao;
import com.itheima.fengkuanglianxi.bookmanager.bookdao.BookDao;
import com.itheima.fengkuanglianxi.bookmanager.domain.Book;

public class BookService {

    private static Book2Dao bookDao = new Book2Dao();

    public boolean isExitsBook(String bookId) {

        Book[] books = bookDao.getAllBooks();

        for (int i = 0; i < books.length; i++) {

            Book bookArray = books[i];
            if(bookArray != null){
                if(bookArray.getBookId().equals(bookId)){
                    return true;
                }
            }

        }
        return false;

    }

    public boolean addBook(Book book) {
        boolean b = bookDao.addBook(book);

        return b;
    }

    public void deleteBook(String bookId) {
        bookDao.deleteBook(bookId);

    }

    public void updateBook(Book book) {
        bookDao.updateBook(book);
    }

    public Book[] getAllBooks() {
        Book[] allBooks = bookDao.getAllBooks();
        return allBooks;
    }
}
